//
//  YJDoctorDetailInfoController.m
//  QuickCure1
//
//  Created by 陶永久 on 2016/10/31.
//  Copyright © 2016年 maoge. All rights reserved.
//

#import "YJDoctorDetailInfoController.h"
#import "YJDoctorsIfonModel.h"
#import "YJDoctordetailInfoView.h"

@interface YJDoctorDetailInfoController ()<UIScrollViewDelegate>

@property (nonatomic, weak) YJDoctordetailInfoView *doctordetailInfoView;

@property (nonatomic, weak) UIScrollView *scrollView;

@property (nonatomic, weak) UILabel *treatCondition; //接诊条件

@property (nonatomic, weak) UILabel *doctorIntro;//医生简介

@property (nonatomic, weak) UIButton *consultButton;

@property (nonatomic, weak) UIView *coverView;

@property (nonatomic, weak) UIView *whiteView;

@end

@implementation YJDoctorDetailInfoController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupUI];
}

#pragma mark - 搭建UI,设置界面
- (void)setupUI
{
    //布局医生详细视图
    [self setupDoctordetailInfoView];
    
    //布局滚动视图
    [self setupScrollView];
    
    [self setupConsultButton];
    
}

#pragma mark -
#pragma mark - 布局咨询按钮
- (void)setupConsultButton
{
    UIButton *consultButton = [UIButton buttonWithType:UIButtonTypeCustom];
    
    self.consultButton = consultButton;
    
    [consultButton setTitle:@"咨询医生" forState:UIControlStateNormal];
    [consultButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    
    [consultButton setBackgroundImage:[UIImage imageNamed:@"nav"] forState:UIControlStateNormal];
    [consultButton setBackgroundImage:[UIImage imageNamed:@"nav"] forState:UIControlStateHighlighted];
    [consultButton addTarget:self action:@selector(clickConsultButton) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:consultButton];
    
    [consultButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.right.equalTo(self.view).offset(-10);
        make.left.equalTo(self.view).offset(10);
        make.height.mas_equalTo(30);
    }];
}

#pragma mark -
#pragma mark - 点击咨询button
- (void)clickConsultButton
{
    if (self.coverView == nil)
    {
        UIView *coverView = [[UIView alloc] init];
        
        self.coverView = coverView;
        
        coverView.backgroundColor = [UIColor blackColor];
        
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)];
        
        [coverView addGestureRecognizer:tap];
        
        coverView.alpha = 0;
        
        UIView *whiteView = [[UIView alloc] init];
        
        whiteView.layer.cornerRadius = 10;
        
        self.whiteView = whiteView;
        
        whiteView.backgroundColor = [UIColor whiteColor];
        
        whiteView.alpha = 0;
        
        [self.view addSubview:coverView];
        [self.view addSubview:whiteView];
        
        UILabel *reminderLabel = [UILabel labelWithTitle:@"温馨提示" andColor:[UIColor blackColor] andFontSize:16];
        reminderLabel.font = [UIFont boldSystemFontOfSize:16];
        
        UILabel *messageLabel = [UILabel labelWithTitle:@"医生关闭了咨询" andColor:[UIColor blackColor] andFontSize:14];
        
        [whiteView addSubview:reminderLabel];
        [whiteView addSubview:messageLabel];
    
        [coverView mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.edges.equalTo(self.view);
        }];
        
        [whiteView mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.width.mas_equalTo(SCREEN_SIZE.width * 0.8);
            
            make.height.mas_equalTo(60);
            
            make.center.equalTo(self.view);
        }];
        
        [reminderLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.centerX.equalTo(whiteView);
            make.bottom.equalTo(whiteView.mas_centerY).offset(-2);

        }];
        
        [messageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(whiteView);
            make.top.equalTo(whiteView.mas_centerY).offset(2);
        }];
        

    }
    
    [UIView animateWithDuration:0.3 animations:^{
        
        self.coverView.alpha = 0.5;
        self.whiteView.alpha = 1;
    }];
    
   
}

#pragma mark -
#pragma mark - 监听手势
- (void)tap:(UITapGestureRecognizer *)tap
{
    [UIView animateWithDuration:0.3 animations:^{
        self.coverView.alpha = 0;
        self.whiteView.alpha = 0;
    } completion:^(BOOL finished) {
        [self.coverView removeFromSuperview];
        [self.whiteView removeFromSuperview];
    }];
}


#pragma mark -
#pragma mark - 布局医生详细页面信息
- (void)setupDoctordetailInfoView
{
    YJDoctordetailInfoView *doctordetailInfoView = [YJDoctordetailInfoView doctordetailInfoView];
    
    doctordetailInfoView.model = self.model;
    
    __weak typeof(self) weakSelf = self;
    
    doctordetailInfoView.clickButtonBlock = ^(NSInteger index)
    {
        [weakSelf.scrollView setContentOffset:CGPointMake((index - 1) * self.view.frame.size.width, 0) animated:YES];
    };
    
    self.doctordetailInfoView = doctordetailInfoView;
    
    [self.view addSubview:doctordetailInfoView];
    
    [doctordetailInfoView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.view);
        make.top.equalTo(self.mas_topLayoutGuideBottom);
        make.height.mas_equalTo(170);
    }];

}

#pragma mark -
#pragma mark - 布局滚动视图
- (void)setupScrollView
{
    //实例化滚动视图
    UIScrollView *scrollView = [[UIScrollView alloc] init];
    
    self.scrollView = scrollView;
    
    scrollView.backgroundColor = [UIColor jq_colorWithHex:0xF4F4F4];
    
    [self.view addSubview:scrollView];
    
    //内容视图
    UIView *contentView = [[UIView alloc] init];
    
    [scrollView addSubview:contentView];
    
    scrollView.pagingEnabled = YES;
    
    scrollView.delegate = self;
    
    scrollView.showsHorizontalScrollIndicator = NO;
    
    //添加label到容器视图
    UILabel *treatCondition = [[UILabel alloc] init];
    
    treatCondition.numberOfLines = 0;
    
    treatCondition.text = @"环境发生的考虑恢复级沙发计算机等放寒假的设计费不记得谁看了不放假不受打击不浪费了几百年电视剧不放假了看到今年发生大;打算看了您付款了单付款你打谁看了;你疯狂女大三房拿到手了那份骄傲的少女级第三看了你看父母都快来撒免费看上的吗";
    
    UILabel *doctorIntro = [[UILabel alloc] init];
    
    doctorIntro.numberOfLines = 0;
    
    doctorIntro.text = @"叫什么力量大发明了什么发客车从模仿大理石;免费卡仕达;父母看到什么;让我们;看电视了疯狂鲁大师可否我]频繁]山东墨龙;独守空房了看电视;;'的是;的缩放你扫;少女大反馈了;盛大发布的时间内看电视那两款;名v都快来没来;率来看了;/没电了父母的老师们女款的女克里斯蒂娜看了;女的收看v德玛萨拉.你看了房;没得撒,.从代课老师;啊;么了; vc,俺的v.麻烦了的什么v/ vkldsmv/ds女开房大厦v,给你看";
    
    [contentView addSubview:doctorIntro];
    
    [contentView addSubview:treatCondition];

    //约束
    [scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.doctordetailInfoView.mas_bottom);
        
        make.left.right.bottom.equalTo(self.view);
        
        make.height.mas_equalTo(self.view.frame.size.height - self.doctordetailInfoView.frame.size.height);
        
        make.width.mas_equalTo(self.view.frame.size.width * 2);
        
    }];
    
    [contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.left.right.equalTo(self.scrollView);
        
        make.width.mas_equalTo(self.view.frame.size.width * 2);
    }];
    
    [treatCondition mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.top.equalTo(scrollView).offset(8);
        
        make.width.mas_equalTo(SCREEN_SIZE.width - 16);
    }];
    
    [doctorIntro mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(scrollView).offset(8);
        
        make.left.equalTo(treatCondition.mas_right).offset(16);
        
        make.width.mas_equalTo(SCREEN_SIZE.width - 16);
    }];
}



#pragma mark -
#pragma mark - 滚动视图的代理方法
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    if (scrollView.isTracking || scrollView.isDragging || scrollView.isDecelerating) {
        
        CGFloat offsetX = scrollView.contentOffset.x;
        
        self.doctordetailInfoView.offsetX = offsetX;
    }
    
}



@end
